# -*- coding: utf-8 -*-
"""
Created on Thu Jun 25 20:40:25 2020

@author: admin
"""

from PIL import Image
import os.path
import glob
import os
import shutil
#import string

path='G:/dataset/人脸/CACD/data/CACD2000/'
save_path = 'G:/dataset/人脸/CACD/data/CACD/'    #保存数据集路径
files=os.listdir(path);
index =1
number =0
for f in files:
    print(f)
    line = f.strip().split('_')
    file_name0 = line[1:-1]
    file_name = "_".join(file_name0) # 根据实际需要使用相应的分隔符连接列表元素,如 , : ; 或者空字符串
    print(file_name)
    if not os.path.exists(os.path.join(save_path,file_name)):
        os.makedirs(os.path.join(save_path,file_name))
        print("目录创建成功！")   
    shutil.move(path+f, os.path.join(save_path+file_name, f))
    print(os.path.join(path, f))
    print(os.path.join(save_path+line[1], f))